home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / XLIB06.ZIP / DEMO8.C < prev    next >
C/C++ Source or Header  |  1993-09-13  |  4KB  |  155 lines

  1. /*************************************************************************
  2.  
  3. DEMO 2
  4.  
  5. Demonstrates the speed difference between compiled bitmap,  conventional
  6. masked planar bitmap, and video bitmap blits.
  7.  
  8. **************************************************************************/
  9.  
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <ctype.h>
  16. #include <alloc.h>
  17. #include <dos.h>
  18. #include <dir.h>
  19. #include <string.h>
  20.  
  21. #include "xlib.h"
  22. #include  "xtext.h"
  23. #include  "xrect.h"
  24.  
  25. /* Macro to make pointer parameters model independent */
  26. #define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))
  27.  
  28. char *swidth[10]={"0","1","2","3","4","5","6","7","8","9"};
  29. char far *fonts[20];
  30. char names[20][20];
  31. int i,fcount=0;
  32.     char c;
  33.  
  34. typedef struct {
  35.   int  dummy;
  36.   char height;
  37.   char width;
  38. } header;
  39.  
  40. void load_user_fonts(){
  41.   FILE *f;
  42.   long len;
  43.   struct ffblk ffblock;
  44.  
  45.   if(findfirst("*.fnt",&ffblock,0)!=0){
  46.     printf("No Fonts found in current directory!\n");
  47.     exit(0);
  48.   };
  49.   do {
  50.     printf("Loading font \"%s\"...\n",ffblock.ff_name);
  51.     strncpy(names[fcount],ffblock.ff_name,14);
  52.  
  53.     f=fopen(ffblock.ff_name,"rb");
  54.  
  55.     fseek(f,0,SEEK_END);
  56.     len=ftell(f);
  57.     fseek(f,0,SEEK_SET);
  58.  
  59.     fonts[fcount] = farmalloc(len);
  60.     if (!fonts[fcount]){
  61.       printf("Out of memory");
  62.       if (fcount!=0){
  63.     printf("- No more fonts can be loaded\n");
  64.     fclose(f);
  65.     goto NoMoreFonts;
  66.       } else printf("\n");
  67.  
  68.       exit(0);
  69.     };
  70.  
  71.     for (i=0;i<len;i++){
  72.       fread(&c,1,1,f);
  73.       *(fonts[fcount]+i)=c;
  74.     }
  75.  
  76.     fclose(f);
  77.     fcount++;
  78.  
  79.   } while (!findnext(&ffblock));
  80.  
  81. NoMoreFonts:
  82.   printf("\n Press 'v' to view, any other key to quit\n");
  83.   c=getch();
  84.   if (c!='V' && c!='v'){
  85.     x_text_mode();
  86.     exit(0);
  87.   }
  88.  
  89.   x_text_init();
  90.   x_set_mode(X_MODE_320x240,0);
  91.   x_register_userfont(fonts[0]);
  92.   x_set_font(2);
  93. }
  94.  
  95.          //......................................//
  96. char *text[30] = {"EXTRACT: Stephen King's \"SALEM'S LOT\" ",
  97.           "",
  98.           "The memory rose up in almost total    ",
  99.           "sensory reference, and for the moment ",
  100.           "of its totality he was paralyzed. He  ",
  101.           "could even smell the plaster and the  ",
  102.           "wild odour of nesting animals. It     ",
  103.           "seemed to him that the plain varnished",
  104.           "door of Matt Burke's guest room stood ",
  105.           "between him and all the secrets of    ",
  106.           "Hell. Then he twisted the knob and    ",
  107.           "pushed the door handle inwards...     ",
  108.           "",
  109.           "ABCDEFGHIJKLMNOPQRSTUVWXYZ            ",
  110.           "abcdefghijklmnopqrstuvwxyz 0123456789 ",
  111.           "~!@#$%^&*()_+|`-=\\{}[]:\";'<>?,./    ",
  112.           NULL};
  113.  
  114.  
  115.  
  116.  
  117.  
  118. void main(){
  119.     int textline;
  120.     int strindex;
  121.     int height;
  122.     load_user_fonts();
  123.  
  124.  
  125.  
  126.     for (i=0;i<fcount;i++){
  127.       x_set_font(FONT_8x8);
  128.       x_rect_fill(0, 0, 319, 239, 0, 0);
  129.       x_line(0,9,319,9,14,0);
  130.       x_line(0,ScrnPhysicalHeight-10,319,ScrnPhysicalHeight-10,14,0);
  131.  
  132.       x_bgprintf(0,0,0,14,0,"Font \"%s\" H=%d,W=%s",names[i],
  133.            (int)*(fonts[i]+2),
  134.            (*(fonts[i]+3)==0)?"Variable":swidth[*(fonts[i]+3)]);
  135.       x_bgprintf(0,ScrnPhysicalHeight-8,0,14,0,
  136.       "Press a key for next font...");
  137.  
  138.       x_register_userfont(fonts[i]);
  139.       x_set_font(FONT_USER);
  140.  
  141.       height=(int)*(fonts[i]+2)+1;
  142.       textline=12;
  143.       strindex=0;
  144.       while(text[strindex]){
  145.        x_printf(0,textline,0,14,text[strindex++]);
  146.        textline+=height;
  147.       }
  148.  
  149.       getch();
  150.     }
  151.  
  152.     x_text_mode();
  153. }
  154.  
  155.